package com.hsh.web;

import com.hsh.bean.Ranking;
import com.hsh.service.RankingService;
import com.hsh.service.impl.RankingServiceImpl;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

public class RankingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig){

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        RankingService rankingService = new RankingServiceImpl();
        List<Ranking> rankings = rankingService.getRankings();
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        request.getSession().setAttribute("rankings",rankings);
        filterChain.doFilter(request,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
